--- title: "6、日志统计" created: 2025-11-28 tags: - 算法 --- # 6、日志统计 ## 题目 [日志统计](https://www.lanqiao.cn/paper/3848/problem/179/) ![[image-de5b0f46.png]] ## 思路分析 ![[image-f7148baf.png]] ## 代码实现 ```cpp #include using namespace std; const int N=1e5+10; int n, d, k; unordered_map> likes; //帖子id 该id的所有点赞情况 set hotPosts; // 存答案id int main() { cin >> n >> d >> k; while(n--) { int ts, id; cin >> ts >> id; likes[id].push_back(ts); } for(auto &p : likes) { vector ×tamps = p.second; sort(timestamps.begin(), timestamps.end()); // 滑动窗口 (没必要前缀和 反而麻烦) for(int i = 0; i < timestamps.size(); i++) { int count = 0; for(int j = i; j < timestamps.size() && timestamps[j] < timestamps[i] + d; j++) { count++; if(count >= k) { hotPosts.insert(p.first); break; } } } } for(int id : hotPosts) { cout << id << endl; } return 0; } ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[2-Learning/02-算法/03-刷题理模型/历年真题 模考特训/第九届 c++ B组 省赛/5、递增三元组|5、递增三元组]] 🏠 [[00-刷题理模型]] ➡️ [[8、乘积最大|8、乘积最大]]